package org.ipti.br.tag.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author Paulo, Lucas
 */
@Entity
public class Enrollment extends AbstractEntity{

    @Column(nullable = false)
    private String mask;

    @OneToOne
    @JoinColumn(name = "personage_id", nullable = false)
    private Personage personage;

    private Long quantity;
    
    public Enrollment() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = "" + this.getMask() + this.getQuantity()
                    + ((this.getPersonage() != null) ? this.getPersonage().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Enrollment(String mask, Personage personage, Long quantity) {
        this.mask = mask;
        this.personage = personage;
        this.quantity = quantity;
    }

    public String getMask() {
        return mask;
    }

    public void setMask(String mask) {
        this.mask = mask;
    }

    public Personage getPersonage() {
        return personage;
    }

    public void setPersonage(Personage personage) {
        this.personage = personage;
    }

    public Long getQuantity() {
        return quantity;
    }

    public void setQuantity(Long quantity) {
        this.quantity = quantity;
    }
}
